package jhavelogger.models;

import jhavelogger.visitor.LogVisitor;

/**
 * Represents a log message that states a connection has been accepted. Example
 * log line: 1/31/08 5:35 PM - INFO: Accepted connection 45 from 141.32.22.39
 * 
 * @author Jared Schlicht
 */
public class AcceptedConnection extends JHaveLog {
    private int uid;
    private String ipAddress;

    /**
     * Constructs a new AcceptedConnection object
     * @param logSource the server that sent this message
     * @param uid the user's per-session identifier
     * @param ipAddress the user's ip address
     */
    public AcceptedConnection(String logSource, int uid, String ipAddress) {
	this.setLogSource(logSource);
	this.setUid(uid);
	this.setIpAddress(ipAddress);
    }

    /**
     * Sets the log's ip address
     * @param ipAddress the ipAddress to set
     */
    public void setIpAddress(String ipAddress) {
	this.ipAddress = ipAddress;
    }

    /**
     * Gets the log's ip address
     * @return the ipAddress
     */
    public String getIpAddress() {
	return ipAddress;
    }

    /**
     * Set's the log's UID
     * @param uid the uid to set
     */
    public void setUid(int uid) {
	this.uid = uid;
    }

    /**
     * Gets the log's UID
     * @return the uid
     */
    public int getUid() {
	return uid;
    }

    @Override
    public Object accept(LogVisitor visitor) {
	return visitor.visit(this);
    }
    
    @Override
    public String toString() {
	return "Accepted Connection on " + this.getLogSource() + ": UID " + this.getUid() + ", IP " + this.getIpAddress();
    }
}
